<?
$picMaxSize = "298*172";
$picMinSize = "529*594";
$action = new Action();
class Action
{
	function Action()
	{
		global $gAct,$gOp;
		switch($gOp)
		{
			case "shwListUser":
				$this->shwListUser();
				break;
			case "update":
			    $this->update();
				break;
			case "export":
			    $this->export();
				break;
			case "ajaxSaveInfo":
			    $this->ajaxSaveInfo();
				break;
			case "ajaxGetInfo":
			    $this->ajaxGetInfo();
			    break;
			case "ajaxStat":
			    $this->ajaxStat();
				break;
			default:
				$this->shwListUser();
				break;
		}
	}
	function ajaxStat()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$picMaxSize,$picMinSize,$_SESSION,$GJson;
		$data = array();
		if($INCOME['et'] && $INCOME['st'] && $INCOME['uid'])
		{
		$sql = "SELECT * FROM res_file where uid=".$INCOME['uid']." and addTime< '".$INCOME['et']."' and addTime > '".$INCOME['st']."' and isGroupTop=0  ";
		$DB->db_query($sql);
		$uploadFileCount = $DB->db_fetch_num();
		$sql = "SELECT * FROM res_file where uid=".$INCOME['uid']." and addTime< '".$INCOME['et']."' and addTime > '".$INCOME['st']."' and isGroupTop=0 and postTime is not null";
		$DB->db_query($sql);
		$pubFileCount = $DB->db_fetch_num();
		$sql = "SELECT * FROM res_file where uid=".$INCOME['uid']." and addTime< '".$INCOME['et']."' and addTime > '".$INCOME['st']."' and isGroupTop>0 ";
		$DB->db_query($sql);
		$uploadBaoCount = $DB->db_fetch_num();
		$sql = "SELECT * FROM res_file where uid=".$INCOME['uid']." and addTime< '".$INCOME['et']."' and addTime > '".$INCOME['st']."' and isGroupTop>0 and postTime is not null";
		$pubBaoCount = $DB->db_fetch_num();
 
		$data = array("uf"=>$uploadFileCount,"pf"=>$pubFileCount,"ub"=>$uploadBaoCount,"pb"=>$pubFileCount);
		}
		 
		echo $GJson->encode($data);
	}
	function ajaxGetInfo()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$picMaxSize,$picMinSize,$_SESSION,$GJson;
		$f = $DB->db_query_first("select * from admin_info where id=".$INCOME['editId']);
		echo $GJson->encode($f);
	}
	function ajaxSaveInfo()
    {
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$picMaxSize,$picMinSize,$_SESSION,$gCurTime;
		$f = $DB->getDBFields($INCOME);
		if($INCOME['editId'])
		{
			$r = $DB->db_query_first("select * from admin_info where name ='".$f['name']."' and id!=".$INCOME['editId']);
			if($r)
			{
				echo "<script>parent.result(-1);</script>";exit;
			}
			if($INCOME['pass'])
			{
				$f['pass'] = md5($INCOME['pass']);
			}
			$f['updateTime'] = $gCurTime;
			$DB->db_form_update("admin_info",$f,"id=".$INCOME['editId'],true);
		}
		else
		{
			$f['addTime'] = $gCurTime;
			if($INCOME['pass'] && $f['name'] && $f['validDate'])
			{
				$r = $DB->db_query_first("select * from admin_info where name ='".$f['name']."'");
				if(empty($r))
				{
					$f['pass'] = md5($INCOME['pass']);
					$DB->db_form_insert("admin_info",$f);
				}
				else
				{
					echo "<script>parent.result(-1);</script>";exit;
				}
			}
		}
	 
		echo "<script>parent.result(1);</script>";
	}
 
	function update()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$picMaxSize,$picMinSize,$_SESSION;
		if($INCOME['id'] && is_numeric($INCOME['dbrubikenScore']) && is_numeric($INCOME['dbbabilunScore']))
		{
			$fields = $DB->getDBFields($INCOME);
			$fields['edtTime'] = date("Y-m-d H:i:s",time());
			$DB->db_form_update("user",$fields,"id=".$INCOME['id']);
			echo "ok";
		}
		else
		{
			echo "err";
		}
	}
	function shwListUser()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$picMaxSize,$picMinSize,$_SESSION;
		 
		if($_SESSION['adminUser']['roleId']!="1")
		{
			//$dealerId = $_SERVER['adminUser']['dealerId'];
			//$conArr[] ="dealerId = '".$_SESSION['adminUser']['dealerId']."'";
		}
		if($INCOME['queryName'])
		{
			$conArr[] =" src = '".$INCOME['queryName']."'";
		}
        
		if($conArr)
		{
			$con ="where ". implode(" and ",$conArr);
		}
		$sql = "SELECT count(*) as num FROM admin_info $con";
		$iPerPage = 10;
		$r = $DB->db_query_first($sql);
		$allNum = $r['num'];
		$pageClass = new MyPage(array (
		'total' => $allNum,
		'perpage' => $iPerPage,
		'url' => $gPageName."?act=".$gAct."&op=".$gOp."&queryName=".$_GET['queryName']
		));
		$page = empty ($INCOME['page']) ? 1 : $INCOME['page'];
		$iStartNo = ($page -1) * $iPerPage;
		$sql = "SELECT * FROM admin_info $con order by id desc LIMIT {$iStartNo}, {$iPerPage}";
		$DB->db_query($sql);
		$data = null;
		$idx = 0+($page-1)*$iPerPage;
		while($r = $DB->db_fetch_row())
		{
		    $idx++;
			$r['disId'] = $idx;
			$r['st'] = "使用中";
 
		    $data[] = $r;	
		}
		$gSmarty->assign("queryName",$INCOME['queryName']);
		$gSmarty->assign("pageNav",$pageClass->show());
		$gSmarty->assign("role",$_SESSION['adminUser']['roleId']);
 		$gSmarty->assign("id",$_SESSION['adminUser']['id']);
		$gSmarty->assign("act",$gAct);
		$gSmarty->assign("picMaxSize",$picMaxSize);
		$gSmarty->assign("picMinSize",$picMinSize);
		$gSmarty->assign("data",$data);
		$gSmarty->display("user/list.tpl");
	}
}
?>